/**
 * User: ct/512799311@qq.com
 * Date: 2017/11/13 0013
 * Time: 上午 11:16
 *
 */

export function addClass(el,className) {
    if(hasClass(el,className)){
        return
    }

    let newClass = el.className.split(' ');
    newClass.push(className);
    el.className = newClass.join(' ');
}

export function hasClass(el,className) {
    let reg = new RegExp('(^|\\s)'+className+'(\\s|$)');
    return reg.test(el.className)
}

export function getData(el,name,val){
  const prefix='data-'
  if(val){
    return el.setAttribute(prefix + name, val);
  }else{
    return el.getAttribute(name)
  }
}
